package com.yzf.utils;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DatetimeUtil {
	public static String getNowDatetime(){
		String nowtime = "";
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");//可以方便地修改日期格式
		nowtime = dateFormat.format( now );
		return nowtime ;
	}
	
	public static String getNowDatetime(String format){
		String nowtime = "";
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(format);//可以方便地修改日期格式
		nowtime = dateFormat.format( now );
		return nowtime ;
	}
	
	public static String getNowDateLongtime(){
		String nowtime = "";
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//可以方便地修改日期格式
		nowtime = dateFormat.format( now );
		return nowtime ;
	}
	
	 public static String dateToStr(java.util.Date dateDate) {
		  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		  String dateString = formatter.format(dateDate);
		  return dateString;
		 }

		 /**
		  * 将短时间格式字符串转换为时间 yyyy-MM-dd 
		  * 
		  * @param strDate
		  * @return
		  */
	 public static Date strToDate(String strDate) {
		  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		  ParsePosition pos = new ParsePosition(0);
		  Date strtodate = formatter.parse(strDate, pos);
		  return strtodate;
		 }
	 
	 public static String dateFormat(String strDate,String format) {
		  SimpleDateFormat formatter = new SimpleDateFormat(format);
		  ParsePosition pos = new ParsePosition(0);
		  Date strtodate = formatter.parse(strDate, pos);
		  String dateString = formatter.format(strtodate);
		  return dateString;
		 }
	
	public static void main(String[] args) {
		DatetimeUtil.getNowDatetime();
	}
}
